
#include "tf_list.h"
#include "tf_log.h"
#include <stdio.h>

#if !defined( DEBUG)
#define DEBUG
#endif

static void print_string_list( string_list* list){
    int i=0;
    for( i=0;i<list->length; ++i){
        printf( "%s %d: %s\n", __func__, i,( get_from_string_list( list, i)));
    }
}

static void print_int_list( array_list* list){
    int i=0;
    for( i=0;i< list->length; ++i){
        printf( "%s %d: %d\n",__func__, i, *((int*)get_from_array_list( list, i)));
    }
}

static void array_list_test(){
    array_list *list=alloc_array_list( 3);
    int i=12;
    set_array_list( list, 0, &i, sizeof(int));
    i=123;
    set_array_list( list, 1, &i, sizeof(int));
    i=321;
    set_array_list( list, 2, &i, sizeof(int));
    i=333;
    push_back_array_list( list, &i, sizeof(int));
    print_int_list( list);

    array_list *lst=alloc_array_list();
    for( i=0;i<5;++i){
        push_back_array_list( lst, &i, sizeof(i));
    }
    print_int_list( lst);
    free_array_list( lst);

    lst=alloc_array_list();
    for( i=0;i<5;++i){
        push_head_array_list( lst, &i, sizeof(i));
    }
    print_int_list( lst);

    free_array_list( list);
}


static void string_list_test(){
    string_list *list=alloc_string_list( 2);
    set_string_list( list, 0, "Hello world");
    set_string_list( list, 1, "Hello");
    push_back_string_list( list, "world");
    print_string_list(list);
    set_string_list( list, 2, "Fuck");
    print_string_list( list);

    string_list *list2= copy_string_list( list);
    INFO_LOG( "Content of array list 1");
    print_string_list( list);

    INFO_LOG( "Content of array list 2 which is copied from 1");
    print_string_list( list2);

    INFO_LOG("Concacted array list");
    string_list *list3=concact_string_list( list, list2);
    print_string_list( list3);

    free_string_list( list);
    free_string_list( list2);
    free_string_list( list3);

    list=alloc_string_list();
    push_back_string_list( list, "one");
    push_back_string_list( list, "two");
    push_back_string_list( list, "three");
    push_back_string_list( list, "four");
    print_string_list( list);
    free_string_list( list);

    list=alloc_string_list();
    push_head_string_list( list, "one");
    push_head_string_list( list, "two");
    push_head_string_list( list, "three");
    push_head_string_list( list, "four");
    print_string_list( list);
    free_string_list( list);

    list=NULL;
    const char* str="etc/home/dir";
    if(string_list_tok( str, &list, "/")==0){
        print_string_list( list);
        free_string_list( list);
    }
}

int main( int argc, char** argv){
//    tf_log_verbose(1); //Enable verbose mode
    string_list_test();
    array_list_test();
    return 0;
}

